import httpRequest from '@/utils/httpRequest'
export default {
  namespaced: false,
  state: {
    dictList: []
  },
  getters: {
    getDictionary: state => (type, exclude) => {
      return handleDictList(state, type, exclude)
    }
  },
  mutations: {
    getDictList (state, list) {
      state.dictList = list
    }
  },
  actions: {
    initialDictList ({commit}) {
      httpRequest({
        url: httpRequest.adornUrl('/sys/dict/list'),
        method: 'get',
        params: httpRequest.adornParams({
          page: 1,
          limit: 999
        }, false)
      }).then(({data}) => {
        if (data && data.code === 0) {
          commit('getDictList', data.page.list)
        }
      })
    }
  }
}

function handleDictList (state, type, exclude = []) {
  return state.dictList.filter(res => res.type === type && exclude.indexOf(res.dicKey) === -1)
}
